package cn.yunhe.action;

import java.util.HashSet;
import java.util.Set;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ExceptionMapping;
import org.apache.struts2.convention.annotation.ExceptionMappings;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import cn.yunhe.entity.Essay;
import cn.yunhe.entity.LoginUser;
import cn.yunhe.service.LoginUserService;

@ParentPackage("struts-default")   
@ExceptionMappings({ @ExceptionMapping(exception = "java.lange.RuntimeException", result = "error") })  
public class LoginUserAction extends BaseAction {
	
	private int loginuserid;
	private String loginusername;
	private String loginuserpassword;
	private Set<Essay> essays=new HashSet<Essay>();
	
	//登录验证
	@Action(value="login", results = { @Result(name = "success", location = "/success.jsp") , @Result(name = "error", location = "/error.jsp")})
	public String login() {
		LoginUserService lus=new LoginUserService();
		LoginUser loginUser=lus.login(loginusername, loginuserpassword);
		if (loginUser!=null) {
			getMapSession().put("loginuser",loginUser);
			System.out.println(loginUser.getLoginusername());
			return SUCCESS;
		}else {
			return ERROR;
		}
	}
	//注册
	@Action(value="reg", results = { @Result(name = "success", location = "/regsucc.jsp") , @Result(name = "error", location = "/error.jsp")})
	public String reg() {
		LoginUserService lus=new LoginUserService();
		Boolean flag=lus.reg(loginusername, loginuserpassword);
		if (flag) {
			return SUCCESS;
		}else {
			return ERROR;
		}
	}

	public String getLoginusername() {
		return loginusername;
	}

	public void setLoginusername(String loginusername) {
		this.loginusername = loginusername;
	}

	public String getLoginuserpassword() {
		return loginuserpassword;
	}

	public void setLoginuserpassword(String loginuserpassword) {
		this.loginuserpassword = loginuserpassword;
	}

	public int getLoginuserid() {
		return loginuserid;
	}

	public void setLoginuserid(int loginuserid) {
		this.loginuserid = loginuserid;
	}

	
	public Set<Essay> getEssays() {
		return essays;
	}

	public void setEssays(Set<Essay> essays) {
		this.essays = essays;
	}
	
}
